package cn.chencq.proxy.timer.handler.custom;

import java.util.HashSet;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.jsoup.Connection.Response;

import cn.chencq.proxy.timer.handler.GeneralProxyHandler;

/**
 * @website http://m.66ip.cn
 * @author chencq
 * @desc 66ip
 * 
 */
public class ProxyHandlerBy66ip extends GeneralProxyHandler {

	@Override
	public String getHandler() {

		return "66IP";
	}

	@Override
	public int parseResp(String rid, Response res) {
		Set<String> proxySet = new HashSet<String>();
		String body = res.body();
		String regex = "((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)\\.){3}(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|[1-9]):\\d{1,4}";
		Pattern p = Pattern.compile(regex);
		Matcher m = p.matcher(body);
		while (m.find()) {
			String proxy = m.group();
			proxySet.add(proxy);
		}
		super.putToCache(rid, proxySet);
		return proxySet.size();

	}

}
